home *** CD-ROM | disk | FTP | other *** search
/ Precision Software Appli…tions Silver Collection 1 / Precision Software Applications Silver Collection Volume One (PSM) (1993).iso / windows / games / bug.arj / BUG.C < prev    next >
Text File  |  1988-06-11  |  5KB  |  162 lines

  1. /*      Windows Program
  2.  
  3.         (C) 1987 C.C.Ryder. Centaur Software Ltd
  4.  
  5. c/bug/..../*
  6. */
  7.  
  8. #include <windows.h>
  9. #include <string.h>
  10. #include <stdlib.h>
  11. #include "bug.h"
  12.  
  13. #define BUFLEN          80
  14.  
  15. long FAR PASCAL bugWndProc( HWND, unsigned, WORD, LONG );
  16. BOOL bugInit( HANDLE);
  17.  
  18. HANDLE hInst;
  19.  
  20. char szClass[BUFLEN];           /* Class Name */
  21.  
  22. int nTimerID;
  23. HANDLE hBug;
  24. int TimeCount=0;
  25. int MaxX,MaxY;
  26. #define NEWX    (rand()/(32767/MaxX))
  27. #define NEWY    (rand()/(32767/MaxY))
  28. /*      RANDVAL(MaxValue,MinValue) */
  29. #define RANDVAL(X,Y)     ((rand()/(32767/(X-Y)))+Y)
  30. #define BUGTIME    1000
  31. WORD hOldCur;
  32. HWND hBuggedWin = NULL;
  33.  
  34. /*      Initializtaion of main program
  35. */
  36. BOOL bugInit( hInstance)
  37. HANDLE hInstance;
  38. {
  39.         PWNDCLASS bugClass;
  40.  
  41.         LoadString( hInstance, IDS_APPNAME, (LPSTR)szClass, BUFLEN );
  42.  
  43.         if ((bugClass = (PWNDCLASS)LocalAlloc( LPTR, sizeof(WNDCLASS))) == (PWNDCLASS)NULL)
  44.                 return(FALSE);
  45.  
  46.         bugClass->lpszClassName = (LPSTR)szClass;
  47.         bugClass->hbrBackground = (HBRUSH)COLOR_WINDOW+1;
  48.         bugClass->style         = CS_VREDRAW | CS_HREDRAW;
  49.         bugClass->hInstance     = hInstance;
  50.         bugClass->lpfnWndProc   = bugWndProc;
  51.         hBug = LoadCursor( hInstance, (LPSTR)"bugger" );
  52.         bugClass->hCursor       =  hBug;
  53.  
  54.         if (!RegisterClass( (LPWNDCLASS)bugClass ) ) {
  55.                 LocalFree( (HANDLE)bugClass );
  56.                 return (FALSE);
  57.         }
  58.  
  59.         LocalFree( (HANDLE)bugClass );
  60.  
  61.         return (TRUE);
  62. }
  63.  
  64.  
  65. long FAR PASCAL bugWndProc( hWnd, message, wParam, lParam)
  66. HWND hWnd;
  67. unsigned message;
  68. WORD wParam;
  69. LONG lParam;
  70. {
  71.         static POINT p;
  72.  
  73.         switch (message)  {
  74.  
  75.         case WM_DESTROY:
  76.                 PostQuitMessage( 0 );
  77.                 break;
  78.         case WM_SETFOCUS:
  79.                 ShowWindow( hWnd, SW_HIDE );
  80.                 break;
  81.  
  82.         case WM_TIMER:
  83.                 if (--TimeCount == 0) {
  84.                         MessageBeep(MB_OK);
  85.                         if (hBuggedWin != NULL) {
  86.                                 SetClassWord(hBuggedWin,GCW_HCURSOR,hOldCur);
  87.                         }
  88.                         SetCursorPos( NEWX,
  89.                                       NEWY);
  90.                         SetCursor(hBug);
  91.                         GetCursorPos((LPPOINT)&p);
  92.                         hBuggedWin = WindowFromPoint(p);
  93.                         hOldCur = SetClassWord(hBuggedWin,GCW_HCURSOR,hBug);
  94.                         TimeCount = RANDVAL(10,1);
  95.                         if (TimeCount == 10) {
  96.                                 TimeCount = 200;        /* hide */
  97.                                 if (hBuggedWin != NULL) {
  98.                                         SetClassWord(hBuggedWin,GCW_HCURSOR,hOldCur);
  99.                                 }
  100.                         }
  101.                 }
  102.                 break;
  103.  
  104.         default:
  105.                 return( DefWindowProc(hWnd, message, wParam, lParam) );
  106.         }
  107.         return( 0L );
  108. }
  109.  
  110. int PASCAL WinMain (hInstance, hPbug, lpszCmdLine, cmdShow)
  111. HANDLE hInstance, hPbug;
  112. LPSTR lpszCmdLine;
  113. int cmdShow;
  114. {
  115.         HWND    hWnd;
  116.         MSG     msg;
  117.  
  118.  
  119.         if (!hPbug) {
  120.                 if (!bugInit( hInstance ))
  121.                         return FALSE;
  122.         }
  123.         else
  124.                 return FALSE;
  125.  
  126.  
  127.         hWnd = CreateWindow(
  128.                 (LPSTR)szClass,   /* The class name */
  129.                 (LPSTR)NULL,  /* The window instance name */
  130.                 WS_OVERLAPPEDWINDOW,
  131.                 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
  132.                 (HWND)NULL,
  133.                 (HMENU)NULL,               /*null parent window parm*/
  134.                 (HANDLE)hInstance,
  135.                 (LPSTR)NULL
  136.             );
  137.  
  138.         hInst = hInstance;
  139.  
  140.         MaxX = GetSystemMetrics(SM_CXSCREEN);
  141.         MaxY = GetSystemMetrics(SM_CYSCREEN);
  142.         /* any other non standard window related inits here */
  143.  
  144.         hBuggedWin = NULL;
  145.         srand(1);
  146.         TimeCount = RANDVAL(10,1);
  147.         nTimerID = SetTimer(hWnd,IDS_TIMER,BUGTIME,(FARPROC)NULL);
  148.         ShowWindow( hWnd, SW_HIDE );
  149.         UpdateWindow(hWnd);
  150.  
  151.  
  152.         while (GetMessage( (LPMSG)&msg, NULL, 0, 0)){
  153.                 TranslateMessage( (LPMSG)&msg );
  154.                 DispatchMessage( (LPMSG)&msg );
  155.         }
  156.  
  157.         /* any closing down here */
  158.         KillTimer(hWnd,IDS_TIMER);
  159.         exit( msg.wParam );
  160. }
  161.  
  162.